﻿-- Author      : Kamil
-- Create Date : 9/20/2012 7:50:31 PM
killsList = {};
kCounter = 0;
kWithNoDeath = 0;


function ShowProfessions(message, sender, distribution)
	if ((message == 'ShowAll') and not (sender == UnitName('player'))) then
		print(sender .. ' poprosił o Twoje profki.');
		LinkAllMyProfessions(distribution);
	end
end

function LinkAllMyProfessions(distribution)
		if (IsUsableSpell("Engineering")) then SendChatMessage(select(2,GetSpellLink("Engineering")),distribution); end
		if (IsUsableSpell("Alchemy")) then SendChatMessage(select(2,GetSpellLink("Alchemy")),distribution); end
		if (IsUsableSpell("Inscription")) then SendChatMessage(select(2,GetSpellLink("Inscription")),distribution); end
		if (IsUsableSpell("Tailoring")) then SendChatMessage(select(2,GetSpellLink("Tailoring")),distribution); end
		if (IsUsableSpell("Leatherworking")) then SendChatMessage(select(2,GetSpellLink("Leatherworking")),distribution); end
		if (IsUsableSpell("Blacksmithing")) then SendChatMessage(select(2,GetSpellLink("Blacksmithing")),distribution); end
		if (IsUsableSpell("Enchanting")) then SendChatMessage(select(2,GetSpellLink("Enchanting")),distribution); end
		if (IsUsableSpell("Jewelcrafting")) then SendChatMessage(select(2,GetSpellLink("Jewelcrafting")),distribution); end
		if (IsUsableSpell("Cooking")) then SendChatMessage(select(2,GetSpellLink("Cooking")),distribution); end
end

function ShowMyLatency(distribution)
	local down, up, lag = GetNetStats();
	SendChatMessage("Latency: "..lag.."ms","GUILD");
end


function RespondToPing(message, sender)
	if not (sender == UnitName('player')) then
		SendAddonMessage(PX_RESPOND_TO_PING, FormatAddonMessage('Respond'), 'WHISPER',sender);
		InviteAutoAccept = true;
	end
end

function InvitePlayer(player)
	InviteUnit(player);
end

function ShowMyStatistics()
	honorableKills, dishonorableKills, highestRank = GetPVPLifetimeStats();
	local ang = floor((honorableKills/TimePlayed)*100)/100;
	SendChatMessage("(Online: "..TimePlayed.."h+) (HK: "..honorableKills..")  ~"..ang.." alluchow na godzine!", "GUILD");
end 

function SetGuildWarningText(text,sender)
	GuildMsgFrame:AddMessage(text, 0.2, 1.0, 0.2, 53, 2);
	DEFAULT_CHAT_FRAME:AddMessage("|cff22ff55[GuildWarning] [" .. sender .. "]: " .. text);
	PlaySoundFile("Interface\\AddOns\\mnk\\Sound\\gw.mp3")
end

function GetPlayerIdLine(player)
	local klasa = '';
	local lvl = '??';
	local gildia = '';
	
	if not (targetList[player] == nil) then 
		klasa = targetList[player].klasa;
		lvl = targetList[player].lvl;
		gildia = targetList[player].gildia;
	end
	
	return player .. " - " .. klasa .. " [" .. lvl .. "] " .. gildia;
end

function GetKillDescription()
	local descriptions = {};
	local chance = 50;
	
	descriptions[0] = ' został zajebany.';
	descriptions[1] = ' padł jak szmata.';
	descriptions[2] = ' już nie wstanie...';
	descriptions[3] = ' nie żyże^^';
	descriptions[4] = ' OWN3D by ' .. UnitName("player");
	descriptions[5] = ' dostał combo na twarz.';
	descriptions[6] = ' -- ' .. UnitName("player") .. ' otwiera sezon na alluchy.';
	descriptions[7] = ' dostał oklep.';
	descriptions[8] = ' nie ogarnął dpsu.';
	descriptions[9] = ' dostał wjep.';
	descriptions[10] = ' umarł w butach.';
	descriptions[11] = ' padł na ryj.';
	descriptions[12] = ' Died Trying.';
	descriptions[13] = ' R.I.P.';
	descriptions[14] = ' nadział sie jak szczerbaty na suchary...';
	
	
	rnd = math.random(1,chance + 14);
	if (rnd <= chance) then rnd = 0;end
	if (rnd > chance) then rnd = rnd - chance;end
	return descriptions[rnd];
end

function NoticePartyKill(player, class, race, zone, sex, lvl)
	SendChatMessage(GetPlayerIdLine(player) .. GetKillDescription(), "GUILD");
	PlaySoundFile("Interface\\AddOns\\mnk\\Sound\\win.mp3")
	local triv = targetList[player].trivial;
	
	killsList[kCounter] = kills(class, race, zone, sex);
	kCounter = kCounter + 1;

	if (triv == false) then
		kWithNoDeath = kWithNoDeath + 1;
	end;
	CheckKillCount();
end

function CheckKillCount()
	 
	if  (kWithNoDeath == 3) then SetKillMsgFrame('Trzy trupy!',kWithNoDeath); elseif 
		(kWithNoDeath == 5) then SetKillMsgFrame('Seryjny morderca!',kWithNoDeath); elseif
		(kWithNoDeath == 10) then SetKillMsgFrame('10 killi bez deada!',kWithNoDeath); elseif 
		(kWithNoDeath == 15) then SetKillMsgFrame('15 trupów na koncie!',kWithNoDeath); elseif
		(kWithNoDeath == 21) then SetKillMsgFrame('Blackjack!',kWithNoDeath); elseif 
		(kWithNoDeath == 25) then SetKillMsgFrame('25 alluchów na sumieniu!',kWithNoDeath); elseif 
		(kWithNoDeath == 30) then SetKillMsgFrame('30! Ja pierdole masakra.',kWithNoDeath); elseif 
		(kWithNoDeath == 40) then SetKillMsgFrame('Czterdziecha na karku!',kWithNoDeath); elseif 
		(kWithNoDeath > 3) then SetKillMsgFrame('COMBO X' .. kWithNoDeath,kWithNoDeath); end
end

function SetKillMsgFrame(txt, kills)
	-- 0 killi = red
	-- 20 killi = green
	KillsMsgFrame:AddMessage(txt, 1-(kills/20), 0 + (kills/20) , 0, 52, 1);
end

function test()
	kWithNoDeath = kWithNoDeath + 1;
	CheckKillCount();
end;

function formatWGTime(seconds)
	local hr;
	local min;
	local sec;
	local formated = 'Trwa, lub brak danych';
	if not (seconds == nil) then
		hr = floor(seconds/3600);
		min = floor((seconds - (hr * 3600))/60);
		sec = floor((seconds - (hr * 3600)) - (min * 60));
		formated = hr .. 'h ' .. min .. 'm ';
	end
	return formated;
end

function requestWGTime()
   SendAddonMessage(PX_WG_REQUEST, FormatAddonMessage('RequestWGTimer'), 'GUILD',nil);
end

function respondWGTime()
	if not (GetWintergraspWaitTime() == nil) then SendAddonMessage(PX_WG_RESPOND, FormatAddonMessage(GetWintergraspWaitTime()), 'GUILD',nil);end
end;

function ratVerify(rat,win,los,timestamp,checksum)
	local result = 0;
	if (genCheckSum(rat,win,los,timestamp) == checksum) then result = 1;end
	return result;
end

function genCheckSum(rat,win,los,timestamp)
	return mod(((win+los)/rat),timestamp);
end

function bgrattest()
	print(genCheckSum(1301,13,1,time()));
end

function bgRattingUp()
	local change = ceil((baseBGRatDefs['up']*((baseBGRatDefs['maxrat']-bgRatting[UnitName('player')].ratting)/1000))*6/5);
	bgRatting[UnitName('player')].wins = bgRatting[UnitName('player')].wins + 1;
	bgRatting[UnitName('player')].timestamp = time();
	bgRatting[UnitName('player')].ratting = bgRatting[UnitName('player')].ratting + change;
	bgRatting[UnitName('player')].checksum = genCheckSum(bgRatting[UnitName('player')].ratting,bgRatting[UnitName('player')].wins,bgRatting[UnitName('player')].looses,bgRatting[UnitName('player')].timestamp);
	setRattingLabels();
	print('|cff22ff55BattleGround Ratting wzrósł o:  |cff44BBAA' .. change .. '.  |cff22ff55Wynosi teraz:  |cff44BBAA' .. bgRatting[UnitName('player')].ratting);
end

function bgRattingDown()
	local change = ceil((baseBGRatDefs['down']*(bgRatting[UnitName('player')].ratting/baseBGRatDefs['maxrat']))*6);
	bgRatting[UnitName('player')].looses = bgRatting[UnitName('player')].looses + 1;
	bgRatting[UnitName('player')].timestamp = time();
	bgRatting[UnitName('player')].ratting = bgRatting[UnitName('player')].ratting - change;
	bgRatting[UnitName('player')].checksum = genCheckSum(bgRatting[UnitName('player')].ratting,bgRatting[UnitName('player')].wins,bgRatting[UnitName('player')].looses,bgRatting[UnitName('player')].timestamp);
	setRattingLabels();
	print('|cff22ff55BattleGround Ratting spadł o: |cffDD0000' .. change .. '. |cff22ff55Wynosi teraz: |cffDD0000' .. bgRatting[UnitName('player')].ratting);
end

